const baseApi = 'http://localhost:10080'

function initData() {
    $.ajax({
        type: 'get',
        url: baseApi + '/getCountPojo',
        data: {},
        dataType: 'json',
        success: function (res) {
            const data = res.data
            $('#sales').text(data.accessCount)
            $('#vistors').text(data.appointmentCount)
            $('#orders').text(data.spaceCount)

            var pieData = [
                {
                    value: data.accessCount,
                    color:"rgba(233, 78, 2, 1)",
                    label: "门禁数量"
                },
                {
                    value : data.appointmentCount,
                    color : "rgba(88, 88, 88,1)",
                    label: "预约数量"
                },
                {
                    value : data.spaceCount,
                    color : "rgba(79, 82, 186, 1)",
                    label: "车位剩余"
                }
            ];
            new Chart(document.getElementById("pie").getContext("2d")).Pie(pieData);
        },
        error: function () {

        }
    });

    $.ajax(
        {
            type: "get",
            url: baseApi + '/getWeekPojo',
            data: {},
            dataType: 'json',
            success: function (res) {
                const data = res.data
                var barChartData = {
                    labels: ["今日", "前一天", "前两天", "前三天", "前四天", "前五天", "前六天"],
                    datasets: [
                        {
                            fillColor: "rgba(233, 78, 2, 0.9)",
                            strokeColor: "rgba(233, 78, 2, 0.9)",
                            highlightFill: "#e94e02",
                            highlightStroke: "#e94e02",
                            data: [data.one, data.two, data.three, data.four, data.five, data.six, data.seven]
                        }

                    ]

                };
                new Chart(document.getElementById("bar").getContext("2d")).Bar(barChartData);
            }
        }
    )


}
